﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Sistema_de_Taller.SDT_DAL.Utilities
{
    public class Vehicle_DAL
    {
        public void VehicleInsert(Common_Files.Definitions.Vehicle Vehicle)
        {
            //EL @ es para dividir una línea de código en 2
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            SqlCommand Command = new SqlCommand(@"insert into Vehicle (Client_ID, Vehicle_Brand, Vehicle_Model, Vehicle_Patent, Vehicle_EngineNumber, Vehicle_SerialNumber, Vehicle_SellDate) 
                                                                values ('" + Vehicle.Client_ID + "', '" + Vehicle.Vehicle_Brand + "', '" + Vehicle.Vehicle_Model + "','" + Vehicle.Vehicle_Patent + "','" + Vehicle.Vehicle_EngineNumber + "', '" + Vehicle.Vehicle_SerialNumber + "', '" + Vehicle.Vehicle_SellDate.ToShortDateString() + "')", Connection);
            Common_Files.Connection.CloseConecction(Connection, Command);
        }

        public DataSet VehicleLoad()
        {
            //EL @ es para dividir una línea de código en 2
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            SqlDataAdapter Command = new SqlDataAdapter(@"Select Vehicle_ID, Vehicle_Brand as 'Marca', Vehicle_Model as 'Modelo', Vehicle_Patent as 'Patente', Vehicle_EngineNumber as 'Número de Motor', Vehicle_SerialNumber as 'Número de Serie', Vehicle_SellDate as 'Fecha de Venta' from Vehicle", Connection);
            DataSet DataSet = new DataSet();
            Command.Fill(DataSet);
            return (DataSet);
        }

        public DataSet VehicleLoadID(UInt32 ClientID)
        {
            //EL @ es para dividir una línea de código en 2
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            SqlDataAdapter Command = new SqlDataAdapter(@"Select Vehicle_ID, Vehicle_Brand as 'Marca', Vehicle_Model as 'Modelo', Vehicle_Patent as 'Patente', Vehicle_EngineNumber as 'Número de Motor', Vehicle_SerialNumber as 'Número de Serie', Vehicle_SellDate as 'Fecha de Venta' from Vehicle where Client_ID = '" + ClientID + "'", Connection);
            DataSet DataSet = new DataSet();
            Command.Fill(DataSet);
            return (DataSet);
        }

        public DataSet VehicleDataIdLoad(UInt32 VehicleID)
        {
            //EL @ es para dividir una línea de código en 2
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            SqlDataAdapter Command = new SqlDataAdapter(@"Select Vehicle_ID, Vehicle_Brand as 'Marca', Vehicle_Model as 'Modelo', Vehicle_Patent as 'Patente', Vehicle_EngineNumber as 'Número de Motor', Vehicle_SerialNumber as 'Número de Serie', Vehicle_SellDate as 'Fecha de Venta' from Vehicle where Vehicle_ID = '" + VehicleID + "' ", Connection);
            DataSet DataSet = new DataSet();
            Command.Fill(DataSet);
            return (DataSet);
        }

        public void VehicleUpdate(Common_Files.Definitions.Vehicle Vehicle)
        {
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            SqlCommand Command = new SqlCommand("update Vehicle set Vehicle_Brand= '" + Vehicle.Vehicle_Brand + "' , Vehicle_Model = '" + Vehicle.Vehicle_Model + "', Vehicle_Patent = '" + Vehicle.Vehicle_Patent + "', Vehicle_EngineNumber = '" + Vehicle.Vehicle_EngineNumber + "' , Vehicle_SerialNumber = '" + Vehicle.Vehicle_SerialNumber + "', Vehicle_SellDate = '" + Vehicle.Vehicle_SellDate.ToShortDateString() + "' where Vehicle_ID = '" + Vehicle.Vehicle_ID + "'", Connection);
            Common_Files.Connection.CloseConecction(Connection, Command);
        }

        public void VehicleDelete()
        {
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            //  SqlCommand Command = new SqlCommand("delete from Vehicle where mov_codigo = '" + DgvDatos.SelectedRows[0].Cells[0].Value.ToString() + "'", Connection);
            //  CloseConecction(Connection, Command);
        }

        public DataSet VehicleSearch(String Parameter, String Column)
        {
            String query = string.Format("Select Vehicle_Brand as 'Marca', Vehicle_Model as 'Modelo', Vehicle_Patent as 'Patente', Vehicle_EngineNumber as 'Número de Motor', Vehicle_SerialNumber as 'Número de Serie', Vehicle_SellDate as 'Fecha de Venta' from Vehicle where {0} like '%" + Parameter + "%'", Column);
            SqlConnection Connection = Common_Files.Connection.OpenConecction();
            SqlDataAdapter Command = new SqlDataAdapter(query, Connection);
            DataSet DataSet = new DataSet();
            Command.Fill(DataSet);
            return (DataSet);
        }
    }
}